<template>
  <div class="container" style="width: 1000px">
    <el-card class="box-card" style="heigth: 50px">
      <el-page-header @back="cancel" content="详情页面"> </el-page-header>
    </el-card>
    <br />
    <el-form>
      <el-card class="box-card">
        <el-row type="flex" class="row-bg">
          <el-col>
            <el-form-item>
              <img
                :src="this.form.articleSurface"
                alt=""
                style="width: 450px; heigth: 250px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item>
              <h1>{{ form.articleTitle }}</h1>
            </el-form-item>

            <el-form-item label="作者：">
              {{ form.articleAuthor }}
            </el-form-item>

            <el-form-item label="简介：">
              {{ form.articleExplain }}
            </el-form-item>

            <el-form-item label="类型：">
              {{ form.articleType }}
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <el-card>
        <el-form-item>
          <mavon-editor
            v-model="form.mdContent"
            :subfield="prop.subfield"
            :defaultOpen="prop.defaultOpen"
            :toolbarsFlag="prop.toolbarsFlag"
            :editable="prop.editable"
            :scrollStyle="prop.scrollStyle"
            :boxShadow="prop.boxShadow"
            ref="md"
          />
        </el-form-item>
      </el-card>
    </el-form>
  </div>
</template>

<script>
import { getArticleDetail } from "../api/article";
import common from "../utils/common";

export default {
  data() {
    return {
      loaclhostPath: common.localhostPath,
      form: {
        articleTitle: "",
        articleExplain: "",
        articleAuthor: "",
        articleType: "",
        articleContent: "", // 转成的html
        mdContent: "", // 输入的markdown
        articleSurface: "",
      },
    };
  },
  methods: {
    //取消
    cancel() {
      this.$router.go(-1);
    },
    getDetail() {
      var id = localStorage.getItem("detailId");
      getArticleDetail(id).then(({ data }) => {
        this.form = data.data[0];
        this.form.articleSurface =
          this.loaclhostPath + data.data[0].articleSurface;
      });
    },
  },
  mounted() {
    this.getDetail();
  },
  computed: {
    prop() {
      let data = {
        subfield: false, // 单双栏模式
        defaultOpen: "preview", //edit： 默认展示编辑区域 ， preview： 默认展示预览区域
        editable: false,
        toolbarsFlag: false,
        scrollStyle: false,
        boxShadow: false, //边框
      };
      return data;
    },
  },
};
</script>

<style scoped>
.container {
  word-wrap: break-word;
  word-break: break-all;
  margin: auto;
}
.el-form-item {
  margin: 0;
}
</style>